/**
 * 坐骑属性配置数据
 * 根据表格数据定义各坐骑在不同转职等级下的属性上限
 */

export interface MountAttributeConfig {
  name: string;
  attributes: {
    ap?: { // 攻击
      initial: number; // 初始属性
      maxLevels: {
        notPromoted: number; // 未转 (等级上限100)
        firstPromotion: number; // 一转 (等级上限120)
        secondPromotion: number; // 二转 (等级上限140)
        thirdPromotion: number; // 三转 (等级上限160)
      };
    };
    hp?: { // 气血
      initial: number;
      maxLevels: {
        notPromoted: number;
        firstPromotion: number;
        secondPromotion: number;
        thirdPromotion: number;
      };
    };
    sp?: { // 精力
      initial: number;
      maxLevels: {
        notPromoted: number;
        firstPromotion: number;
        secondPromotion: number;
        thirdPromotion: number;
      };
    };
    speed?: { // 速度
      initial: number;
      maxLevels: {
        notPromoted: number;
        firstPromotion: number;
        secondPromotion: number;
        thirdPromotion: number;
      };
    };
  };
}

export const MOUNT_ATTRIBUTE_CONFIGS: MountAttributeConfig[] = [
  {
    name: "战马",
    attributes: {
      ap: {
        initial: 2750,
        maxLevels: {
          notPromoted: 2750,
          firstPromotion: 4142,
          secondPromotion: 5930,
          thirdPromotion: 8162,
        },
      },
      speed: {
        initial: 50,
        maxLevels: {
          notPromoted: 50,
          firstPromotion: 77,
          secondPromotion: 108,
          thirdPromotion: 143,
        },
      },
    },
  },
  {
    name: "乌云踏雪",
    attributes: {
      hp: {
        initial: 13550,
        maxLevels: {
          notPromoted: 13550,
          firstPromotion: 20510,
          secondPromotion: 29450,
          thirdPromotion: 40610,
        },
      },
      ap: {
        initial: 3500,
        maxLevels: {
          notPromoted: 3500,
          firstPromotion: 5116,
          secondPromotion: 7156,
          thirdPromotion: 9668,
        },
      },
    },
  },
  {
    name: "绝影",
    attributes: {
      hp: {
        initial: 13550,
        maxLevels: {
          notPromoted: 13550,
          firstPromotion: 20510,
          secondPromotion: 29450,
          thirdPromotion: 40610,
        },
      },
      sp: {
        initial: 13550,
        maxLevels: {
          notPromoted: 13550,
          firstPromotion: 20510,
          secondPromotion: 29450,
          thirdPromotion: 40610,
        },
      },
    },
  },
  {
    name: "里飞沙",
    attributes: {
      ap: {
        initial: 3500,
        maxLevels: {
          notPromoted: 3500,
          firstPromotion: 5116,
          secondPromotion: 7156,
          thirdPromotion: 9668,
        },
      },
      speed: {
        initial: 100,
        maxLevels: {
          notPromoted: 100,
          firstPromotion: 132,
          secondPromotion: 168,
          thirdPromotion: 208,
        },
      },
    },
  },
  {
    name: "夜照玉狮子",
    attributes: {
      hp: {
        initial: 13550,
        maxLevels: {
          notPromoted: 13550,
          firstPromotion: 20510,
          secondPromotion: 29450,
          thirdPromotion: 40610,
        },
      },
      speed: {
        initial: 100,
        maxLevels: {
          notPromoted: 100,
          firstPromotion: 132,
          secondPromotion: 168,
          thirdPromotion: 208,
        },
      },
    },
  },
  {
    name: "的卢",
    attributes: {
      hp: {
        initial: 17100,
        maxLevels: {
          notPromoted: 17100,
          firstPromotion: 25180,
          secondPromotion: 35380,
          thirdPromotion: 47940,
        },
      },
    },
  },
  {
    name: "爪黄飞电",
    attributes: {
      sp: {
        initial: 17100,
        maxLevels: {
          notPromoted: 17100,
          firstPromotion: 25180,
          secondPromotion: 35380,
          thirdPromotion: 47940,
        },
      },
    },
  },
  {
    name: "燎原火",
    attributes: {
      ap: {
        initial: 5000,
        maxLevels: {
          notPromoted: 5000,
          firstPromotion: 7064,
          secondPromotion: 9608,
          thirdPromotion: 12680,
        },
      },
    },
  },
  {
    name: "赤兔胭脂兽",
    attributes: {
      speed: {
        initial: 150,
        maxLevels: {
          notPromoted: 150,
          firstPromotion: 187,
          secondPromotion: 228,
          thirdPromotion: 273,
        },
      },
    },
  },
];

/**
 * 转职等级对应的最大等级
 */
export const PROMOTION_MAX_LEVELS = {
  notPromoted: 100, // 未转
  firstPromotion: 120, // 一转
  secondPromotion: 140, // 二转
  thirdPromotion: 160, // 三转
};

/**
 * 根据坐骑名称获取属性配置
 */
export function getMountAttributeConfig(mountName: string): MountAttributeConfig | null {
  return MOUNT_ATTRIBUTE_CONFIGS.find(config => config.name === mountName) || null;
}

/**
 * 计算坐骑属性
 * 公式：(当前转职等级上限属性 - 初始属性) / 当前转职等级上限 * 当前等级取整数
 */
export function calculateMountAttribute(
  initialValue: number,
  maxValue: number,
  maxLevel: number,
  currentLevel: number
): number {
  const levelRatio = Math.floor(currentLevel) / maxLevel;
  return Math.floor(initialValue + (maxValue - initialValue) * levelRatio);
}
